<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

<title>文档管理--文档列表</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" href="css/luyan/luyan.css" type="text/css"></link>
<link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
<link rel="stylesheet" href="easyui/themes/default/easyui.css"
	type="text/css"></link>
<script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">

	$(function(){
		$.post("folder/findAllUser.do",
		function(data){
			user=data;
			init();
		},"json");
	  });
	  function init(){
	  	var deptid = "deptid="+$("#userdeptid").val();
			$("#div2").dialog({closed:true});
			$("#div3").dialog({closed:true});
			
	  		$("#dg").datagrid({
	  			url:"folder/findAll.do?"+deptid,
	  			striped:true,	  			
	  			rownumbers:true,
	  			title:"文档列表",
	  			pagination:true,
	  			pageList:[10,20,50],
	  			columns:[[{
	  				title:"名称",
	  				field:"name",
	  				width:190,
	  				align:"right",
	  				formatter:function(value,row){
	  				
	  					return "<a href='files/go.do?folderid="+row.id+"'>"+value+"</a>";
	  				}
	  			},{
	  				title:"类型",
	  				field:"w",
	  				width:200,
	  				align:"center",
	  				formatter:function(){
	  					return "文件夹";
	  				}
	  			},{
	  				title:"所有者",
	  				field:"userid",
	  				width:100,
	  				align:"right",
	  				formatter:function(value){
	  					for(var i=0;i<user.length;i++){
	  						if(value==user[i].id){
	  							return user[i].name;
	  						}
	  					}
	  				}
	  			},{
	  				title:"创建时间",
	  				field:"createdate",
	  				width:100,
	  				align:"right",
	  				formatter:date
	  			},{
	  				title:"操作",
	  				field:"id",
	  				width:168,
	  				align:"right",
	  				formatter:function (value,row,index){
						return "<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
						}	  				
	  			}]],
	  			toolbar:[{text:"新增文件夹",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}] 	
	  		});
	  	//点击按钮动态查询
	  	$("#btn").click(function(){
	  		var name = $("#name2").val();
	  		var userdeptid = $("#userdeptid").val();
	  		var createdate = $("#createdate2").val();
	  		var data = "name="+name+
  						"&userdeptid="+userdeptid+
  						"&createdate="+createdate;
	  		$("#dg").datagrid({
	  			url:"folder/findByParam.do?"+data
	  		});
	  	
	  	});
	  	$("#div3").dialog({
		    title: "修改",
		    width: 400,
		    height: 350,
		    closed: true,
		    buttons:[{
				text:"修改",
				handler:function(){
					var data ="id="+$("#id1").val()+
					"&name="+$("#name1").val()+
					"&path="+$("#path1").html()+
	  				"&userid="+$("#userid").val()+
	  				"&createdate="+$("#createdate1").html()+
	  				"&deptid="+$("#deptid10").val();
					$.get("folder/update.do",data,function(data){
								alert(data);
								$("#div3").dialog("close");
								$("#dg").datagrid("reload");
							},"text");  	
				}
			},{
				text:"取消",
				handler:function(){
					$("#div3").dialog("close");
				}
			}]
		});	
	  
	  }
	  	function add(){
	  	$("#sp").html(date1());
		$("#div2").dialog({
  			title:"添加文件夹",
  			width:400,
  			heigeht:200,
  			closed:false,
  			modal:true,
  			buttons:[{text:"确定",
  					handler:function(){
  					
  						var data = "name="+$("#name3").val()+
  						"&path="+$("#userdeptname").val()+
  						"&deptid="+$("#userdeptid").val()+
  						"&userid="+$("#userid").val()+
  						"&createdate="+$("#sp").html();
  							$.post(
  								"folder/add.do",
  								data,
  								function(data){
  								alert(data);
  									$("#div2").dialog("close");
  									$("#dg").datagrid("reload");
  								},
  								"text"
  							);
  					}
  					},
  					{text:"取消",
  					handler:function(){
  							$("#div2").dialog("close");
  						}
  					}]
  		});
		}
	
	 	function update(value){
			
			$("#div3").dialog("open");	
			$.post("folder/findByid.do","id="+value,function(data){
			$.post("users/findById.do","id="+data.userid,function(data){
  				$("#userid1").html(data.name);
  			},"json");
  				$("#id1").val(value);
  				$("#name1").val(data.name);
  				$("#path1").html(data.path);
  				var re= date(data.createdate);
  				$("#createdate1").html(re);
  				$("#userid1").html(data.userid);
  				$("#deptid10").val(data.deptid);
  			},"json");
		};
		function del(value){
			$.messager.confirm("提示框", "你确定要删除吗?",function(r){
				if(r){
					var data = "id="+value;
					$.post(
		  				"folder/delete.do",
		  				data,
		  				function(data){
		  				alert(data);
		  				$("#dg").datagrid("reload");
		  				
		  				},
		  				"text"
		  			);
				}
			});
		};
		function date(value){
			return value.year+1900+"-"
			+(value.month+1)+"-"+value.date;
		}
	    function upload(){
	     $("#myform").submit();
			
		}
		function date1(){
		var date1 = new Date();
		var tt = ""+date1.getFullYear()+"-";
		tt+=(date1.getMonth()+1)+"-";
		tt+=date1.getDate()+" ";
		tt+=date1.getHours()+":";
		tt+=date1.getMinutes()+":";
		tt+=date1.getSeconds();
		return tt;
		}
</script>

</head>
<body style="height: 800px" id="mainbody">

 <p style="margin-bottom: 20px"><img src="css/luyan/img/icons/contacts.png" width="32px" height="32px"/>&nbsp;&nbsp;<span>文档管理</span></p>   
<div id="mycontent" >
		<div class="content">
			<div id="u4" style="margin-left: 0px;width: 700px">
				文件名：<input id="name2" name="name2" type="text" style="width: 70px" />
				创建日期：<input id="createdate2"
					name="createdate2" type="text" style="width: 70px" /> <input
					id="btn" type="button"
					style="width: 50px;height: 20px;font-size: 10px" value="检索" />
			</div>

		</div>
	    <table id="dg" ></table>
	
		<table id="dg" cellpadding="0" cellspacing="0" style="margin-right: 1000px">
		</table>
		<!-- 新增文件夹 -->
		<div id="div2">
			文件夹名：<input id="name3" name="name3" type="text" /><br />
			<br /> 路径：/文档管理/${user.deptname}/<br />
			<br /> 创建人：${user.name}<br />
			<br /> 创建时间：<span id="sp"></span>
		</div>
		<!-- 修改文件夹 -->
		<div id="div3">
			<input type="hidden" name="folder.id" id="id1"> 文件夹名：<input
				id="name1" name="name1" type="text" /><br />
			<br /> 路径：<span id="path1"></span><br />
			<br /> 创建人：<span id="userid1"></span><br />
			<br /> 创建时间：<span id="createdate1"></span><br />
			<br /> <input id="deptid10" type="hidden" />
		</div>


	</div>
	<input type="hidden" value="${user.id}" id="userid" />
	<input type="hidden" value="${user.name}" id="username" />
	<input type="hidden" value="${user.deptid}" id="userdeptid" />
	<input type="hidden" value="${user.deptname}" id="userdeptname" />
</body>
</html>
